package com.supply.dl.widget.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import com.chad.library.adapter.base.BaseViewHolder;
import com.supply.dl.R;
import com.supply.dl.bean.NotJobInfo;

import java.util.ArrayList;

public class MaterielChangeNoReciyviewAdapter extends RecyclerView.Adapter<MaterielChangeNoReciyviewAdapter.MyViewHolder>
{
	private Context mContext;
	private ArrayList<NotJobInfo> notJobInfos = new ArrayList<>();
	public OnItemClickListener onItemClickListener;
	private int selectedPostion;

	public interface OnItemClickListener
	{
		void onItemClickListener(int position);
	}

	public MaterielChangeNoReciyviewAdapter(Context context, ArrayList<NotJobInfo> notJobInfos, OnItemClickListener onItemClickListener, int select)
	{
		this.mContext = context;
		this.notJobInfos = notJobInfos;
		this.onItemClickListener = onItemClickListener;
		this.selectedPostion = select;
	}

	@Override public MaterielChangeNoReciyviewAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
	{
		return new MaterielChangeNoReciyviewAdapter.MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_materiel, parent, false));
	}

	@Override public void onBindViewHolder(MaterielChangeNoReciyviewAdapter.MyViewHolder holder, final int position)
	{
		if (notJobInfos.size() > 0)
		{
			holder.txtName.setText(notJobInfos.get(position).skuName);
			holder.txtName.setOnClickListener(new View.OnClickListener()
			{
				@Override public void onClick(View v)
				{
					onItemClickListener.onItemClickListener(position);
				}
			});
			if (selectedPostion == position)
				holder.txtName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.supply_shape_selected_btn));
			else
				holder.txtName.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.supply_shape_default_btn));
		}
	}

	@Override public int getItemCount()
	{
		return notJobInfos.size();
	}

	class MyViewHolder extends BaseViewHolder
	{
		@BindView(R.id.txt_name) TextView txtName;

		public MyViewHolder(View itemView)
		{
			super(itemView);
			txtName = (TextView) itemView.findViewById(R.id.txt_name);
		}
	}

	public void setPosition(int position)
	{
		this.selectedPostion = position;
		notifyDataSetChanged();
	}
}
